import { Controller, Inject, Get, Post, Body } from '@midwayjs/core';
import { LoginService } from "@service/login.service";
import { LoginDTO } from "@dto/login.dto";

@Controller('/')
export class LoginController {
  @Inject()
  loginService: LoginService;

  // 生成验证码，转64位输出
  @Get('/captchaImage')
  async generateCode() {
    return this.loginService.captchaImage()
  }

  /** 登录、在接收数据前，先验证是否符合LoginDTO格式规则 */
  @Post('/login')
  async login(@Body() body: LoginDTO) {
    return this.loginService.login(body);
  }

  /** 退出登录 */
  @Post('/logout')
  async logout() {
    return this.loginService.logout();
  }
}
